<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/pages/common/taglib.jsp"%>
<%@ include file="/WEB-INF/pages/common/back-common.jsp"%>
<%@ include file="/WEB-INF/pages/common/jquery2.1.4.jsp"%>
<%@ include file="/WEB-INF/pages/common/back-dialog.jsp"%>
<html>
    <head>
        <title>创建</title>
         <script type='text/javascript' src="<ls:templateResource item='/resources/common/js/jquery.validate.js'/>" ></script>
         <link rel="stylesheet" type="text/css" media="screen" href="${contextPath}/resources/common/css/errorform.css" />
		 <link href="<ls:templateResource item='/resources/plugins/select2-4.0/select2.css'/>" rel="stylesheet"/>
		 <script src="<ls:templateResource item='/resources/plugins/select2-4.0/select2.full.min.js'/>" type="text/javascript"></script>
		 <script src="<ls:templateResource item='/resources/plugins/select2-4.0/i18n/zh-CN.js'/>" type="text/javascript"></script>
		 <script src="<ls:templateResource item='/resources/plugins/select2-4.0/makeSelect2.js'/>" type="text/javascript"></script>
         <script language="javascript">
		    $.validator.setDefaults({
		    });
		  var  contextPath = '${contextPath}';
            $(document).ready(function() {
            jQuery("#form1").validate({
                    rules: {
                    userName: {
                        required: true,
                    }
                },
                messages: {
                    userName: {
                        required: "请选择组员"
                    }
                }
            });

                //斑马条纹
                 $("#col1 tr:nth-child(even)").addClass("even");
                makeSelect2(contextPath + "/admin/adminUser/userListForTeam/${projectId}","#userName","项目成员","value","key");

                 //binding Submit
             $("#Submit").click(function(){
             if($("#form1").valid()){
             var formData = $("#form1").serialize();
               $.ajax({
                  type: 'post', // 提交方式 get/post
                  url:  "${contextPath}/admin/projectMember/save", // 需要提交的 url
                  data: formData,
                  dataType : 'json',
                  error: function(jqXHR, textStatus, errorThrown) {
                     alert("保存失败" + textStatus);
                },
                  success: function(data) { // data 保存提交后返回的数据，一般为 json 数据
                      // 此处可对 data 作相关处理
                      if("success" == data){
                            layer.msg("保存成功");
                            closeDialog();
                      }else{
                            layer.msg("保存失败");
                      }

                  }
              });
              return false; // 阻止表单自动提交事件
            };
            });

        });
    
	function closeDialog(){
		var index = parent.layer.getFrameIndex("updateProjectMember"); //先得到当前iframe层的索引
		parent.layer.close(index); //再执行关闭   
		if(parent.sendData){
			parent.sendData();//异步
		}else{
			parent.location.reload();
		}
	}
	
	
	
</script>
</head>
    <body>
        <form action="<ls:url address='/admin/projectMember/save'/>" method="post" id="form1">
            <input id="id" name="id" value="${projectMember.id}" type="hidden">
            <input id="projectId" name="projectId" value="${projectId}" type="hidden">
            <div align="center">
            <table border="0" align="center" class="${tableclass}" id="col1" style="width: 600px">
                <thead>
                    <tr class="sortable">
                        <th colspan="2">
                            <div align="center">
                                	创建项目成员
                            </div>
                        </th>
                    </tr>
                </thead>
			<tr>
		        <td>
		          	选择组员: <font color="ff0000">*</font>
		       	</td>
		        <td>
		            <select name="userName" id="userName" multiple="multiple"  style="width: 480px;">
					   <c:if test="${not empty projectMember.userName}">
					   	  <option value="${projectMember.userName}">${projectMember.userRealName}</option>
					   	</c:if>
				   </select>
		        </td>
			</tr>
			<tr>
		        <td>
		          	职位
		       	</td>
		        <td>
		            <select id="roleId" name="roleId"  class="${selectclass}">
		           		<ls:optionGroup type="select" required="false" cache="true"
	                      beanName="STAFF_POSITION" selectedValue="${projectMember.roleId}"/>
		           	</select>
		        </td>
			</tr>
                <tr>
                    <td colspan="2">
                        <div align="center">
                             <input type="button" name="Submit" id="Submit"  value="提交" />
                            <input type="button" value="关闭" onclick="javascript:closeDialog()" />
                        </div>
                    </td>
                </tr>
            </table>
           </div>
        </form>
    </body>
</html>

